package group2assignone.model;

/**
 * models a booking
 * @author group2
 */
public class Booking
{
    private TicketComponent ticket;
    boolean multipleFlights = false;
    String bookingNum;

    public Booking(String bookingNum)
    {
        this.bookingNum = bookingNum;
    }


    public void addFlight(String flightNum, String username)
    {
        if (ticket == null)
        {
            ticket = new Ticket(flightNum, username);
        }
        else if (!multipleFlights)
        {
            TicketComponent t = ticket;
            ticket = new TicketComposite();
            ticket.addTicket(t);
            multipleFlights = true;
            ticket.addTicket(new Ticket(flightNum, username));
        }
        else
        {
            ticket.addTicket(new Ticket(flightNum, username));
        }
    }

    public void addFlight(String flightNum)
    {
        if (ticket == null)
        {
            ticket = new Ticket(flightNum, "guest");
        }
        else if (!multipleFlights)
        {
            TicketComponent t = ticket;
            ticket = new TicketComposite();
            ticket.addTicket(t);
            ticket.addTicket(new Ticket(flightNum, "guest"));
            multipleFlights = true;
        }
        else
        {
            ticket.addTicket(new Ticket(flightNum, "guest"));
        }
    }

    public String getBookingNum() {
        return bookingNum;
    }

    public void makeBooking()
    {
       ticket.bookTicket(bookingNum);
    }
    
//    public void setTicketComponent(TicketComponent ticket)
//    {
//        this.ticket = ticket;
//    }
//
//    public TicketComponent getTicketComponent()
//    {
//        return ticket;
//    }
}
